/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mediaCache;

import java.util.HashMap;
import javafx.scene.media.Media;

/**
 *
 * @author Irzh
 */
public class MediaCache {
    
    // --------- Singeltone implementation.
    private MediaCache(){
        mediaCache = new HashMap<String , CacheEntry>();
    }
    
    static private MediaCache mc = new MediaCache();
    
    static public MediaCache get(){
        return mc;
    }
    // ------------------------------------
    
    private HashMap<String , CacheEntry> mediaCache;
    
    public boolean isMediaExists(String id){
        if(mediaCache.get(id)!=null){
            return true;
        }
        return false;
    }
    
    public void addMedia(Media media , String id){
        if(!mediaCache.values().contains(media)){
            mediaCache.put(id, new CacheEntry(media));
        }
    }
    
    public Media getMedia(String id){
        return mediaCache.get(id).getMedia();
    }
}
